home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
news
/
readers
/
skim-0.8
/
skim-0
/
skim-0.8.4
/
CheckForDebris.h
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-18
|
2KB
|
79 lines
/*
* NAME
* CheckForDebris.h
* DESCRIPTION
* A bit of trickery to check for memory leaks. The idea is that the
* implementation of every class #defines CLASS_NAME, includes this file
* and calls IncrementObjectCount() and DecrementObjectCount() whenever
* it creates or destroys an object. When the program exits normally, the
* object count of every class is checked and an error is reported if the
* count is > 0.
*
* This functionality is only in effect when skim is compiled in its
* development environment (when NDEBUG is not defined).
* COPYRIGHT
* Skim - Off-line news reading package optimized for slow lines.
* Copyright (C) 1996 Rene W.J. Pijlman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* VERSION
* Skim version 0.8.4.
*/
#include <stdio.h>
#ifdef NDEBUG
# define IncrementObjectCount()
# define DecrementObjectCount()
#else
static Boolean ObjectCountInitialized = False;
static Natural NumberOfObjects = 0L;
# define IncrementObjectCount() \
{ \
if (!ObjectCountInitialized) InitializeObjectCount(); \
NumberOfObjects++; \
}
# define DecrementObjectCount() \
{ \
if (!ObjectCountInitialized) InitializeObjectCount(); \
assert(NumberOfObjects > 0); \
NumberOfObjects--; \
}
static void CheckForDebris( int ExitStatus, void * ClientData )
{
if ( ExitStatus == EXIT_SUCCESS && NumberOfObjects != 0 )
{
fprintf( stderr,
"Warning: %lu %s object%s not destroyed\n",
NumberOfObjects, CLASS_NAME,
NumberOfObjects > 1 ? "s were" : " was" );
}
}
static void InitializeObjectCount( void )
{
if ( on_exit( CheckForDebris, NULL ) != 0 )
{
fprintf( stderr, "Cannot register function with on_exit()\n" );
}
ObjectCountInitialized = True;
}
#endif